package com.lmt_17;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UDPServer {
    public static void main(String[] args) throws Exception {
        System.out.println("server start");
        DatagramSocket  socket = new DatagramSocket(1234);
        byte []bytes = new byte[1024];
        DatagramPacket packet = new DatagramPacket(bytes,bytes.length);
        socket.receive(packet);
        // 获取本次数据包多少数据
        int len = packet.getLength();
        System.out.println(packet.getAddress());
        System.out.println(packet.getPort());
        String s = new String(packet.getData(), 0, len,"UTF-8");
        System.out.println(s);
        socket.close();
    }
}
